package download;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class test {
	  @Test
	    public void downloadAFile() throws Exception {
		  WebDriver driver=new InternetExplorerDriver();
		  FileDownloader downloadTestFile = new FileDownloader(driver);
	        driver.get("http://f.xunlei.com/210427026/file/120819ba-32ee-40d1-8422-534a8af1ffae");
	        WebElement downloadLink = driver.findElement(By.id("downBtn"));
	        String downloadedFileAbsoluteLocation = downloadTestFile.downloadFile(downloadLink);
	        System.out.println("downloadedFileAbsoluteLocation:"+downloadedFileAbsoluteLocation);
	        Assert.assertTrue(new File(downloadedFileAbsoluteLocation).exists());
	        Assert.assertTrue(downloadTestFile.getHTTPStatusOfLastDownloadAttempt()==200);
	    }
	     
	    @Test
	    public void downloadAnImage() throws Exception {
	    	 WebDriver driver=new InternetExplorerDriver();
	    	FileDownloader downloadTestFile = new FileDownloader(driver);
	        driver.get("http://f.xunlei.com/210427026/file/120819ba-32ee-40d1-8422-534a8af1ffae");
	        WebElement image = driver.findElement(By.cssSelector("div.src > a>img"));
//	        System.out.println(image.getAttribute("src"));
	        String downloadedImageAbsoluteLocation = downloadTestFile.downloadImage(image);
	        System.out.println(downloadedImageAbsoluteLocation);
	        Assert.assertTrue(new File(downloadedImageAbsoluteLocation).exists());
	        Assert.assertTrue(downloadTestFile.getHTTPStatusOfLastDownloadAttempt()==200);
	    }
}

